package com.project.controller;

import com.project.dao.PRdao;
import com.project.po.PostrecordInfo;

import com.project.po.postrecord;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class PrController {

    @Resource
    private PRdao pRdao;

    @RequestMapping("/add")
    @ResponseBody
    //显示员工评价信息
    public List<postrecord> add(@RequestParam("eid") String eid,
                                @RequestParam("pchangedate") String pchangedate,
                                @RequestParam("pchangebefore") String pchangebefore,
                                @RequestParam("pchangeafter") String pchangeafter) throws ParseException {
        postrecord post=new postrecord();
        post.setEid(eid);
        post.setPchangeafter(pchangeafter);
        post.setPchangebefore(pchangebefore);

        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        Date date=ft.parse(pchangedate);
        post.setPchangedate(date);

        List<postrecord> postrecords = pRdao.add(post);
        return postrecords;

    }

    @RequestMapping("/")
    @ResponseBody
    public String home(){
        return "hello!";
    }

    /**
     * 查询所有的postrecord记录
     * @return
     */
    @RequestMapping("/PostRecord")
    @ResponseBody
    //显示所有任职情况
    public List<PostrecordInfo> showInfo(){
        List<PostrecordInfo> postrecords = pRdao.getAll();
        return postrecords;

    }

    /**
     * 查询eid的postrecord的记录
     * @param eid
     * @return
     */
    @RequestMapping("/Search")
    public List<PostrecordInfo> Search(@RequestParam("eid") String eid){
        List<PostrecordInfo> postrecords = pRdao.getPostRecord(eid);
        return postrecords;
    }

    /**
     * 打印到Excel中
     * @throws Exception
     */
    @RequestMapping("/exportExel")
    public void exploreExcel() throws Exception {
        List<PostrecordInfo> postrecords=pRdao.getAll();
        pRdao.exportExel("1",postrecords);
    }

}
